/**
 * @file:          Logger.h
 * @brief:
 * @details:
 * @author:        wjh
 * @date created:  2023.09.05
 * @version:       1.0.0
 * @par copyright (c):
 *
 * @par history (desc):
 *   version:1.0.0, wjh, 2023.09.05,14:31:40
 */

#ifndef _LOGGER_H_
#define _LOGGER_H_

/* Include Files **************************************************************/
#include "Datatype.h"
#include "DriverList.h"

/* Macro Definition ***********************************************************/
#define LOG_TABLE_NUM_SIZE 100
#define LOG_TYPE_STR_SIZE 10
#define LOG_NAME_SIR_SIZE 10
#define LOG_DATA_SEND_BUFF_SIZE 100

/* Data Type Define ***********************************************************/
typedef struct
{
    void *addr;
    uint8_t bytes;
    char *type;
    char *name;
} LogDataUnit;

typedef struct
{
    uint8_t head;
    uint8_t data_nums;
    void *data;
    uint8_t check_sum;
    uint8_t end;
} LogDataPackFrame;

typedef struct Logger
{
    /* public data */
    Mcu *mcu;
    uint16_t param_en;
    struct
    {
        union
        {
            uint16_t all;
            struct
            {
                uint8_t minor;
                uint8_t major;
            } byte;
        } number;
        char *release_date;
    } param_version;
    uint16_t param_continuous_send;
    uint16_t param_sample_interval_n;
    uint8_t param_data_head;
    uint32_t param_n_pack_to_send;

    LogDataUnit data_table[LOG_TABLE_NUM_SIZE];
    LogDataPackFrame data_pack_frame;
    uint8_t data_nums;
    uint8_t data_max_num;
    uint16_t data_total_bytes;
    uint16_t tick;
    uint8_t check_sum;
    uint8_t send_buff[LOG_DATA_SEND_BUFF_SIZE];
    uint16_t trigger;
    uint8_t send_len;
    uint8_t updated;
    uint32_t pack_index;

    /* private data */

    /* public method */
    void (*ConfigParam)(struct Logger *self);
    void (*Init)(struct Logger *self);
    void (*Run)(struct Logger *self);
    void (*RegisterVariableToTable)(struct Logger *self, uint8_t data_num, void *data_addr, uint8_t data_bytes, char *data_type, char *name);

    /* private method */

} Logger;

/* Variable Declare ***********************************************************/

/* Function Declare ***********************************************************/
void Logger_Init(struct Logger *self);
void Logger_Run(struct Logger *self);
void Logger_RegisterVariableToTable(struct Logger *self, uint8_t data_num, void *data_addr, uint8_t data_bytes, char *data_type, char *name);

#endif